import { util } from "../../common/util";
import { config } from "../../config";

const state = {//数据
  userInfo: util.getLocalStorage('userInfo_' + config.appName) || {}, // 用户信息 头像 昵称
}

const getters = {//获取数据
  getUserInfo: state => state.userInfo,
}

const mutations = {//对本地无需ajax的更改，使用mutations
  updateUserInfo (state, changed) {
    state.userInfo = changed;
		if(JSON.stringify(changed) == '{}')
			util.delLocalStorage('userInfo_' + config.appName);
		else
			util.setLocalStorage('userInfo_' + config.appName, changed);
  },
}

const actions = {//action好处适合异步操作，action先执与后端交互，mutations后执行
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
